@import "colors";
@import "common";
@import "advanced-add-download-form";
@import "task-filter-settings-form";

// Weird stuff happens when the contents of the popup change the size of the actual popup's container.
// In particular, stuff gets extra weird over some internal arbitrary height limit that Chrome has, an
// the popup might end up with two scroll bars, which is pretty sad. Experimentally, 500px is below
// the cutoff. To experience the weirdness for yourself, raise this limit really high then add a bunch
// of task list items until it's well over the limit for scrolling and then try to scroll.
$mystery-chrome-height-limit: 500px;

* {
  box-sizing: border-box;
}

html {
  background-color: $color-background;
  color: $color-text;
}

button:not(.disabled):not(:disabled) {
  cursor: pointer;
}

body {
  // Reset for Chrome.
  margin: 0;
}

html,
body,
#body,
.popup {
  // Using 100% here should work, but it doesn't. The browser popup must do something weird
  // such that it changes width depending on the contents, even when it's 100% of the <html>
  // width (which is explicitly specified). :/
  width: 400px;
  max-height: $mystery-chrome-height-limit;
}

.popup {
  display: flex;
  flex-direction: column;

  header {
    flex-shrink: 0;
    white-space: nowrap;
    display: flex;
    align-items: center;
    padding: 5px;
    transition: box-shadow 100ms;
    border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    box-shadow: 0 1px 2px 2px rgba(0, 0, 0, 0);

    .description {
      white-space: initial;
      margin-right: auto;
      margin-left: 3px;
      display: flex;
      align-items: center;

      .fa {
        font-size: 21px;
      }

      .left-icon {
        margin-left: 2px;
        margin-right: 8px;
      }

      .right-icon {
        margin-left: 8px;
        margin-right: 2px;
      }
    }

    button {
      margin-left: 2px;

      &.called-out {
        animation-name: shadow-glow;
        animation-duration: 1s;
        animation-iteration-count: infinite;
        animation-timing-function: ease-in-out;
        animation-direction: alternate;
      }
    }

    &.with-shadow {
      box-shadow: 0 1px 2px 2px rgba(0, 0, 0, 0.2);
    }
  }

  .display-settings {
    flex-shrink: 0;
    max-height: 0px;
    transition: max-height 300ms;
    overflow: hidden;

    &.is-visible {
      max-height: 1000px;
      border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    }

    h4 {
      margin-left: 15px;
    }

    .task-filter-settings-form {
      select {
        margin-right: 15px;
      }
    }

    .clear-completed-tasks-button {
      margin-left: 15px;
      margin-bottom: 10px;

      .fa {
        margin-left: 5px;
        font-size: 14px;
      }
    }
  }

  .popup-body {
    flex: 1;
    overflow-y: auto;
    position: relative;
    min-height: 50px;

    &.with-foreground {
      min-height: 400px;

      > :not(.add-download-overlay) {
        filter: blur(1px);
      }
    }
  }
}

.fatal-error {
  .further-explanation,
  textarea {
    margin: 10px 10px 0;
  }

  textarea {
    width: calc(100% - 20px);
    height: 3em;
  }
}

.download-tasks {
  .hidden-count {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 5px;
    margin-bottom: 10px;

    &:hover {
      text-decoration: underline;
      cursor: pointer;
    }
  }

  ul {
    list-style: none;
    margin: 0;
    padding: 0;

    li.task {
      padding: 8px;

      .header {
        display: flex;
        align-items: center;
        margin-bottom: 5px;

        .name-and-status {
          padding-right: 5px;
          margin-right: auto;
          overflow: hidden;

          .name,
          .status {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }

          .name {
            font-weight: 500;
          }

          .status {
            font-size: 0.8em;
            color: $color-text-faded;

            .error-icon {
              margin-right: 3px;
            }
          }
        }

        .remove-button {
          color: $color-error;
        }

        .remove-button,
        .pause-resume-button {
          .fa {
            font-size: 14px;
          }

          &:not(:last-child) {
            margin-right: 3px;
          }
        }
      }

      .status {
        .status-icon {
          margin-right: 4px;
        }
      }

      .progress-bar {
        height: 5px;
        border-radius: 2px;
        position: relative;

        .bar-fill {
          position: absolute;
          top: 0;
          left: 0;
          bottom: 0;
          border-radius: inherit;

          &.in-progress {
            background-color: $color-loading;
          }

          &.completed {
            background-color: $color-success;
          }

          &.errored {
            background-color: $color-error;
          }

          &.unknown {
            background-color: $color-indeterminate;
          }
        }

        .bar-background {
          position: absolute;
          top: 0;
          left: 0;
          bottom: 0;
          right: 0;
          background-color: rgba(0, 0, 0, 0.1);
        }
      }

      &:not(:hover) .header {
        .remove-button,
        .pause-resume-button {
          display: none;
        }
      }
    }
  }
}

.popup-body .add-download-overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;

  .backdrop {
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    filter: blur 0.5px;
  }

  .overlay-content {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px;
  }

  .advanced-add-download-form {
    height: 100%;

    .download-path {
      flex: 1;
    }
  }
}

@keyframes shadow-glow {
  0% {
    box-shadow: 0 0 2px 2px fade-out($color-loading, 1);
  }

  100% {
    box-shadow: 0 0 2px 2px fade-out($color-loading, 0.3);
  }
}
